package com.company.example.interceptor;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimeAspect {
	private static final Logger log = LoggerFactory.getLogger(TimeAspect.class);
	
	/*@Pointcut("@annotation(com.company.example.interceptor.TimeTag)")
	public void methodTime() {
		
	}*/
	
//	@Around("@annotation(com.company.example.interceptor.TimeTag)")
//	@Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
//	@Around("methodTime()")
	public Object around(ProceedingJoinPoint pjp) throws Throwable{
		log.info(pjp.getTarget().getClass().getName());
		
		long start = System.currentTimeMillis();
		log.info("*******执行开始，方法名是：【"+ pjp.getSignature().getName() +"】*********");
		
		Object obj = pjp.proceed();//执行目标方法
		
		long end = System.currentTimeMillis();
		log.info("************调用此方法耗时：【"+(end - start)+"毫秒】**************");
		return obj;
	}
	
}
